package com.lin.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Created by Lin Weihong
 * @date on 2022/5/13 12:59
 */
@Configuration
public class GateWayConfig {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        routes.route("path_route_lin",
                predicateSpec -> predicateSpec.path("/guonei") //对应yml的predicates
                        .uri("http://news.baidu.com/guonei"))//对应的uri
                        .build();
        return routes.build();
    }

    @Bean
    public RouteLocator customRouterLocator2(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        routes.route("path_route_lin2", predicateSpec -> predicateSpec.path("/guoji").uri("http://news.baidu.com/guoji")).build();
        return routes.build();
    }
}
